// Copyright Epic Games, Inc. All Rights Reserved.

#include "SDFGen.h"
#include "Core.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "FTTFUtils.h"
//#include "VfxTextAssetUtils.h"

#define LOCTEXT_NAMESPACE "FSDFGenModule"

void FSDFGenModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

	// Get the base directory of this plugin
	FString BaseDir = IPluginManager::Get().FindPlugin("SDFGen")->GetBaseDir();

	// Add on the relative location of the third party dll and load it
	FString LibraryPath;
#if PLATFORM_WINDOWS
	//LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SDFGenLibrary/Win64/opencv_world480.dll"));
	//编辑器使用的Dll可以放在Source里面
	//如果Dll需要被打包到Runtime使用，就需要先放置在Plugin/Binaries里面
	//LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/SDFGenLibrary/opencv/x64/vc16/bin/opencv_world480.dll"));
#elif PLATFORM_MAC
	// ... dylib
#elif PLATFORM_LINUX
	// ... so
#endif // PLATFORM_WINDOWS

	//OpenCVDllHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;

	// if (OpenCVDllHandle)
	// {
	// 	UE_LOG(LogTemp, Log, TEXT("OpenCV Dll load succ."));
	// }
	// else
	// {
	// 	UE_LOG(LogTemp, Error, TEXT("OpenCV Dll load failed."));
	// }

	// 初始化freetype
	SDFGen::FTTFUtils::Init();
}

void FSDFGenModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
	SDFGen::FTTFUtils::Release();

	// Free the dll handle
	// FPlatformProcess::FreeDllHandle(OpenCVDllHandle);
	// OpenCVDllHandle = nullptr;
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FSDFGenModule, SDFGen)
